﻿// Copyright (c) egmkang wang. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.


namespace XServer.SDK.Net
{
    using System;

    /// <summary>
    /// 客户端和服务器通讯的消息头(LittleEndian)
    /// 只有四个字节的长度, 其中高八位保留, 有效长度字段为低24bit
    /// </summary>
    public struct CSHead
    {
        public CSHead(int length = 0, ushort msgid = 0)
        {
            this.length = length;
            this.msgid = msgid;
        }
        public Int32 length;
        public UInt16 msgid;

        public Int32 RealLength()
        {
            return length & Constant.MSG_LEN_MASK;
        }

        public UInt16 MsgID()
        {
            return this.msgid;
        }

        public void Clear()
        {
            this.length = 0;
            this.msgid = 0;
        }
    }

    /// <summary>
    /// 收到的客户端消息
    /// </summary>
    public struct CSMessage
    {
        public CSMessage(ushort msgid, byte[] buffer, long milliSeconds)
        {
            this.msgid = msgid;
            this.buffer = buffer;
            this.milliSeconds = milliSeconds;
        }
        public ushort msgid;       //消息名称
        public byte[] buffer;      //消息
        public long milliSeconds;  //收到消息的时间戳
    }
}
